package com.ostrich.cloud.ostrichGoodsService.app.ApiImp;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.isuyu.boot.oss.starter.autoconfigure.service.OssService;
import com.ostrich.cloud.common.result.PageResult;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.TypeDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.PutTypeParam;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.SelectTypeParam;
import com.ostrich.cloud.ostrichGoodsService.client.TypeClient;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.AddTypeParam;
import com.ostrich.cloud.ostrichGoodsService.service.GoodsService;
import com.ostrich.cloud.ostrichGoodsService.service.TypeService;
import com.ostrich.cloud.ostrichGoodsService.service.param.CreateTypeParam;
import com.ostrich.cloud.ostrichGoodsService.service.param.GetTypeParam;
import com.ostrich.cloud.ostrichGoodsService.service.param.UpdateTypeParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;

@RestController
@Slf4j
public class TypeApiImp  implements TypeClient {

    @Resource
    private OssService ossService;

    @Resource
    private TypeService typeService;



    @Override
    public void createType(AddTypeParam param) {

        CreateTypeParam createTypeParam = BeanUtil.copyProperties(param, CreateTypeParam.class);

        typeService.createType(createTypeParam);

    }

    @Override
    public String upLoad(MultipartFile file) throws IOException {
        Snowflake snowflake = IdUtil.getSnowflake(2, 2);
        String s = snowflake.nextIdStr();
        String upload = ossService.upload(s+".jpg", file.getInputStream());
        log.info(upload);
        return upload;
    }

    @Override
    public PageResult<TypeDto> getAllTypeDto(SelectTypeParam param) {
        GetTypeParam getTypeParam = BeanUtil.copyProperties(param, GetTypeParam.class);

        PageResult<TypeDto> allType = typeService.getAllType(getTypeParam);
        return allType;
    }

    @Override
    public Boolean delType(Integer typeId) {

        Boolean bool =typeService.delType(typeId);
        return bool;
    }

    @Override
    public Boolean updateType(PutTypeParam param) {

        UpdateTypeParam updateTypeParam = BeanUtil.copyProperties(param, UpdateTypeParam.class);

        Boolean bool=typeService.updateType(updateTypeParam);

        return bool;

    }


}
